package com.cg.design.graphicdesignpattern.flyweight;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;

/**
 * 表示”大型字符“的类
 *
 * @program: LeetCode->BigChar
 * @description: 表示”大型字符“的类
 * @author: cg
 * @create: 2022-04-03 16:26
 **/
public class BigChar {

    /**
     * 字符名字
     */
    private final char charName;
    /**
     * 大型字符对应的字符串（由'#' '。' '\n'组成）
     */
    private String fontData;

    /**
     * 构造函数
     * @param charName
     */
    public BigChar(char charName) {
        this.charName = charName;
        try {
            BufferedReader reader = new BufferedReader(new FileReader("src\\com\\cg\\design\\flyweight\\big" + charName + ".txt"));
            String line;
            StringBuffer buffer = new StringBuffer();
            while ((line = reader.readLine()) != null) {
                buffer.append(line);
                buffer.append("\n");
            }
            reader.close();
            this.fontData = buffer.toString();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    /**
     * 显示大型字符
     */
    public void print() {
        System.out.println(fontData);
    }

}
